package net.appsec.webapp.dao.impl;

import java.util.List;

import net.appsec.webapp.bean.Customer;
import net.appsec.webapp.dao.BasicSqlSupport;
import net.appsec.webapp.dao.CustomerDAO;

import org.springframework.stereotype.Repository;

@Repository("customerDAO")
public class CustomerDAOImpl extends BasicSqlSupport implements CustomerDAO {
	final String NAMESPACE = "net.appsec.webapp.config.mybatis.mapper.Customer.";

	public boolean add(Customer customer) throws Exception {
		int count = this.sqlSession.insert(
				"net.appsec.webapp.config.mybatis.mapper.Customer.add",
				customer);
		return count > 0;
	}

	public boolean update(Customer customer) throws Exception {
		int count = this.sqlSession.update(
				"net.appsec.webapp.config.mybatis.mapper.Customer.update",
				customer);
		return count > 0;
	}

	public boolean delete(Customer customer) throws Exception {
		int count = this.sqlSession.delete(
				"net.appsec.webapp.config.mybatis.mapper.Customer.delete",
				customer);
		return count > 0;
	}

	public Customer load(Integer id) {
		Customer customer = (Customer) this.sqlSession.selectOne(
				"net.appsec.webapp.config.mybatis.mapper.Customer.load", id);
		return customer;
	}

	public Customer get(Customer customer) {
		List<Customer> customers = this.sqlSession.selectList(
				"net.appsec.webapp.config.mybatis.mapper.Customer.get",
				customer);
		return customers.size() > 0 ? (Customer) customers.get(0)
				: customers == null ? null : null;
	}
}